<?php

include_once dirname(dirname(__FILE__)) . '/include/common.php';
$phone = isset($_POST["phone"]) ? addslashes(trim($_POST["phone"])) : '';
$zen_order_id = isset($_POST["zen_order_id"]) ? intval($_POST["zen_order_id"]) : 0;
$core = new core();
if ($phone == "") {
    echo json_encode(array('type' => 1, 'msg' => "Vui lòng điền số phone!"));
    die;
} else {
    $customer = $core->getCustomerInfoByPhone($phone);
    if ($customer) {
        $customer_order = $core->checkCustomerOrder($customer->customer_id,$zen_order_id);
        $customer_order_id = 0;
       if($customer_order){
           $has_order =1;
           $customer_order_id = $customer_order->customer_order_id;
       }else{
           $has_order =0;
       }
        echo json_encode(array('type' => 0, 'customer_fb_name' => $customer->facebook_name,"customer_address"=>  stripslashes($customer->address),
            'customer_id'=>$customer->customer_id,'customer_province'=>$customer->province,
            'phone'=>$phone,'customer_email'=>$customer->email,'customer_name'=>$customer->name,'customer_wholesale'=>$customer->wholesale,
            'has_order'=>$has_order,'customer_order_id'=>$customer_order_id));
        die;
    } else {
        echo json_encode(array('type' => 1, 'msg' => "Khách hàng chưa có trong hệ thống!"));
        die;
    }
}
?>